package cn.edu.hqu.cst.crj.eventmechanism;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import android.view.View.OnClickListener;


public class MainActivity extends AppCompatActivity implements View.OnClickListener{
    Button btn1,btn2,btn3,btn4,btn5,btn7,btn8;
    TextView headtext;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        //显示当前点击按钮
        headtext=findViewById(R.id.head_text);

        //activity作为监听器
        btn1 = findViewById(R.id.button1);
        btn1.setOnClickListener(this);

        //内部类作为监听器
        btn2 = findViewById(R.id.button2);
        btn2.setOnClickListener(new EnterClickListener());

        //匿名内部类作为监听器
        btn3 = findViewById(R.id.button3);
        btn3.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                headtext.setText(getText(R.string.text3));
            }
        });

        //LAMBDA表达式作为监听器
        btn4 = findViewById(R.id.button4);
        btn4.setOnClickListener(view -> headtext.setText(getText(R.string.text4)));

        //外部类作为监听器
        btn5 = findViewById(R.id.button5);
        btn5.setOnClickListener(new Claculator(this,headtext));

        //显示系统信息
        btn7 = findViewById(R.id.button7);
        btn7.setOnClickListener(this);

        //显示进度条
        btn8 = findViewById(R.id.button8);
        btn8.setOnClickListener(this);


    }

    //监听器绑定标签
    public void getResult(View view){
        headtext.setText(getText(R.string.text6));
    }

    @Override
    //activity作为监听器
    public void onClick(View v) {
        Intent intent=new Intent();
        switch(v.getId()){
            case R.id.button1:
                headtext.setText(getText(R.string.text1));
                break;
            case R.id.button7:
                intent.setClass(MainActivity.this, ConfigurationTest.class);
                startActivity(intent);
                break;
            case R.id.button8:
                intent.setClass(MainActivity.this, ProgressDialogTest.class);
                startActivity(intent);
                break;
        }

    }

    //内部类
    class EnterClickListener implements android.view.View.OnClickListener{

        @Override
        public void onClick(View v) {
            headtext.setText(getText(R.string.text2));
        }


    }
}
